{% load files %}
{% load help %}
{% get_admin_help_list for files as help_list %}

{% if help_list %}
<span class="popup_container floatright">
	<span class="popup_title"><a><img src="{{STATIC_URL}}images/help.png" height=32></a></span>
	<span class="left_over_popup">
		{% if help_list %}
		<p>{{'Questions related to Files:'|spacify}}</p>
		<ul>
		{% for faq in help_list %}
				<li><a class="FAQ_Question" name="{{faq.question_link}}" href="{{faq.url}}" target="_blank">{{faq.question|spacify}}</a></li>
		{% endfor %}
		</ul>
		{% else %}
		<p>{{'There is no help yet for this'|spacify}}</p>
		{% endif %}
	</span>
</span>
{% endif %}

{% if not 'hide_title' in options %}
<h1>
	Manage Files for {{Object}}
</h1>
{% endif %}

{% if not 'hide_upload_form' in options %}				
	{% render_file_form for Object %}
{% endif %}

{% if not 'hide_edit_form' in options %}
<form action='.' method='post'>{% csrf_token %}
<input type="hidden" name="next" value="{{ request.path }}" />

{% get_file_count for Object as file_count  %}
{% if file_count %}
	<table border="0" class="small_table" style="text-align: left;">
	{% for form in Forms %}
		<tr>
			<th rowspan=4>
				<a href="{{form.instance.url}}">{% if form.instance.image_type %}<img src="{{form.instance.url}}" height=136>
				{% else %}<img src="{{STATIC_URL}}images/files/{{form.instance.icon}}" height=136>
				{% endif %}</a>
			</th>
		<th colspan="100%" class="left_justify border-bottom"><h2>{{form.instance.filename}}</h2></th>
			<th>
				<button type="submit" class="button DeleteButton smallbutton floatright" name="DeleteFile" value="{{ form.instance.id }}"  title="Delete This File">X</button>
			</th>
		</tr>
		{{form.as_table}}
		<tr>
			<th>Accessed as:</th>
			<td>&#123;&#123;Files.{{form.instance.template_title}}&#125;&#125;</td>
		</tr>
	{% endfor %}
		</table>
{% else %}<p>No files have been uploaded</p>
{% endif %}
<table>
<tr>
    <td colspan="4" class="Buttons left_justify">
		<button type="submit" class="button SaveButton" name="Save" value="SaveEdit" title="Save the updates made to these files">Save</button>
		<a class="button button SaveButton" href="{{next}}">Cancel</a>
		<br>Use this Save button only to save changes to files
    </td>
</tr>
</table>
</form>
{% else %}
	{% get_file_list for Object as Files %}
	{% if Files %}
		<ul>
			{% for file in Files %}
				<li><a href="{{file.url}}">{{file.title}}</a>{% if file.description %} - {{file.description}}{% endif %}</li>
			{% endfor %}
		</ul>
	{% endif %}
{% endif %}

